<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="./axios.js"></script>
  <title>Document</title>
</head>

<body>
  <div id="app">
    <p v-for="item in items" :key="item.id">{{item.name}}</p>
  </div>
  <script src="../vue.js"></script>
  <script>
    //axios默认配置  通过axios的defaults属性设置axios默认配置
    axios.defaults.baseURL = 'https://api.it120.cc/conner';
    axios.defaults.timeout = 3000;
    
    // 请求阶段 添加一个拦截器
    axios.interceptors.request.use(function (config) {
      console.log('请求拦截了');
      return config;
    }, function (error) {
      return Promise.reject(error);
    });

    // 在响应阶段 添加一个响应拦截
    axios.interceptors.response.use(function (response) {
      console.log('响应拦截了');
      return response;
    }, function (error) {
      return Promise.reject(error);
    });
    const app = new Vue({
      el: '#app',
      data: {
        items: []
      },
      created() {
        this.fentchItem();
      },
      methods: {
        fentchItem() {
          axios({
            method: 'post',
            url: '/shop/goods/list/v2',
            data: {},
            headers: {
              // 'X-Requested-With': 'XMLHttpRequest',
              'content-type': 'x-www-form-urlencoded'
            }
          }).then(res => {
            this.items = res.data.data.result
          }).catch(err => {
            console.log('请求失败了');
          })
        }
      }
    })
  </script>
</body>

</html>